package com.oleg.bigidoc.db;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Connection {
	private EntityManager em;
	private EntityManagerFactory emf;
	 
    private EntityManager getEntityManager() {
        if (emf == null) {
            emf = Persistence.createEntityManagerFactory("JSF2Contract");
        }
        return emf.createEntityManager();
    }
		
	public EntityManager getConnection(){
		if(em == null){
			em = getEntityManager();
		}
		System.out.println("em: "+em.toString());
		return em;	
	}
	
	public void Close(){
		System.out.println("em: Close");
		em.clear();
		em.close();
		em = null;
	}
}